<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 直接替换原型对象
    function Person(name, age) {
      this.name = name;
      this.age = age;
    }
    var parent = {
      sayHello: function () {
        console.log("方式1:替换原型对象");
      }
    }

    Person.prototype = parent;
    var p = new Person("张三", 50);
    // p.sayHello();
    console.log(p)

    // 混入式原型继承
    function Student(name, age) {
      this.name = name;
      this.age = age;
    }
    var parent2 = {
      sayHello: function () {
        console.log("方式2:原型继承之混入式加载成员");
      }
    }
    for (var k in parent2) {
      Student.prototype[k] = parent2[k];
    }
    var p2 = new Student("张三", 50);
    // p.sayHello();
    console.log(p2)
  </script>
</body>

</html>